package useragent

import "gitee.com/liumou_site/GoUserAgent/devices"


// GenerateOption 生成选项函数类型
type GenerateOption func(*generateOptions)

// WithDevice 指定设备类型
func WithDevice(device DeviceType) GenerateOption {
	return func(o *generateOptions) {
		o.deviceTypes = []DeviceType{device}
	}
}

// WithOS 指定操作系统
func WithOS(os OS) GenerateOption {
	return func(o *generateOptions) {
		o.osList = []OS{os}
	}
}

// WithBrowser 指定浏览器
func WithBrowser(browser Browser) GenerateOption {
	return func(o *generateOptions) {
		o.browsers = []Browser{browser}
	}
}

// WithMultipleDevices 指定多个设备类型
func WithMultipleDevices(devices ...DeviceType) GenerateOption {
	return func(o *generateOptions) {
		o.deviceTypes = devices
	}
}

// WithMultipleOS 指定多个操作系统
func WithMultipleOS(oss ...OS) GenerateOption {
	return func(o *generateOptions) {
		o.osList = oss
	}
}

// WithMultipleBrowsers 指定多个浏览器
func WithMultipleBrowsers(browsers ...Browser) GenerateOption {
	return func(o *generateOptions) {
		o.browsers = browsers
	}
}

// WithBrand 指定设备品牌
func WithBrand(brand devices.DeviceBrand) GenerateOption {
	return func(o *generateOptions) {
		o.brands = []devices.DeviceBrand{brand}
		o.useDeviceInfo = true
	}
}

// WithMultipleBrands 指定多个设备品牌
func WithMultipleBrands(brands ...devices.DeviceBrand) GenerateOption {
	return func(o *generateOptions) {
		o.brands = brands
		o.useDeviceInfo = true
	}
}

// WithDeviceModel 指定具体设备型号
func WithDeviceModel(brand devices.DeviceBrand, model string) GenerateOption {
	return func(o *generateOptions) {
		o.deviceInfo = &DeviceInfo{
			Brand: brand,
			Model: model,
		}
		o.useDeviceInfo = true
	}
}

// WithDeviceInfo 使用完整的设备信息
func WithDeviceInfo(info *DeviceInfo) GenerateOption {
	return func(o *generateOptions) {
		o.deviceInfo = info
		o.useDeviceInfo = true
	}
}

// WithModels 指定品牌的型号列表
func WithModels(brand devices.DeviceBrand, models []string) GenerateOption {
	return func(o *generateOptions) {
		if o.models == nil {
			o.models = make(map[devices.DeviceBrand][]string)
		}
		o.models[brand] = models
		o.useDeviceInfo = true
	}
}

// WithModelsMap 指定多个品牌的型号映射
func WithModelsMap(models map[devices.DeviceBrand][]string) GenerateOption {
	return func(o *generateOptions) {
		o.models = models
		o.useDeviceInfo = true
	}
}
